import UploaderImg from '@/components/iz-aloss-uploader-img/iz-aloss-uploader-img.vue'
export default {
	components: {
		UploaderImg
	},
	data() {
		return {
			signList: [],
			goodsList: [],
			orderId: ''
		}
	},
	onLoad(options) {
		this.goodsList = JSON.parse(options.list)
		this.orderId = options.orderId
		this.goodsList.forEach(item => {
			item.star = 5
		})
		this.getCommentSign()
	},
	methods: {
		async getCommentSign() {
			var res = await this.$get('server/index/getbiaoqian', {
				page: 1,
				limit: 100
			});
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}
			this.signList = res.list
		},
		onSignClick(item, signItem) {
			item.signId = signItem.id
			this.$forceUpdate()
		},
		async onSubmit() {
			// [{"name":"苏泊尔吸尘器家用","type":3,"goods_id":13,"text":"挺好的，不错","xing":5,"biaoqian":"好评","biaoqianid":1,"id":22}]
			var isText = this.goodsList.some(item => !item.text)
			var isStar = this.goodsList.some(item => !item.star)
			var isSign = this.goodsList.some(item => !item.signId)

			console.log('isText', isText)
			console.log('isStar', isStar)
			console.log('isSign', isSign)

			if (!isText && !isStar && !isSign) {

			} else {
				this.$toast('请补全评价内容')
			}

			var list = []
			this.goodsList.forEach(item => {
				var obj = {}
				obj.name = item.name
				obj.type = item.type,
					obj.goods_id = item.id
				obj.text = item.text
				obj.xing = item.star
				obj.biaoqian = ''
				obj.biaoqianid = item.signId
				obj.id = this.orderId
				list.push(obj)
			})

			console.log('list', list)
			var res = await this.$post('server/index/pingjia', {
				id: this.orderId,
				list: JSON.stringify(list)
			});
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}
			this.$toast('提交成功')
			setTimeout(() => {
				uni.navigateBack()
				uni.$emit('uploadStore')
			}, 800)
		}
	}
}
